import type {
  ComponentRecordType,
  GenerateMenuAndRoutesOptions,
} from '@vben/types';

import { generateAccessible } from '@vben/access';
import { preferences } from '@vben/preferences';

import { message } from '#/adapter/naive';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';

const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');

// 通用化：直接返回所有页面和菜单，不做任何权限校验
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
  const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
  const layoutMap: ComponentRecordType = {
    BasicLayout,
    IFrameView,
  };
  // 直接返回所有页面和菜单
  return {
    menus: await getAllMenusApi(),
    routes: Object.keys(pageMap).map((key) => ({
      path: key.replace('../views', '').replace('.vue', ''),
      component: pageMap[key],
      meta: {},
    })),
  };
}

export { generateAccess };
